package com.lanju.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lanju.commom.EntityConvertUtil;
import com.lanju.dao.AreaCommunityDao;
import com.lanju.entity.Community;
import com.lanju.entity.CommunityImg;
import com.lanju.model.CommunityModel;
import com.lanju.service.AreaCommunityService;

@Service
public class AreaCommunityServiceImpl implements AreaCommunityService{

	@Autowired
	private AreaCommunityDao areaCommunityDao;
	
	@Override
    @Transactional(value="financialmarketingTM", rollbackFor = Exception.class)
	public Map<String, Object> addAreaCommunity(Map<String, Object> param) {
		Map<String, Object> map=new HashMap<String, Object>();
		Community ac=new Community();
		ac.setArea_name(param.get("area_name").toString());
		ac.setCommunity_desc(param.get("community_desc").toString());
		ac.setCommunity_name(param.get("community_name").toString());
		ac.setCreate_time(new Date());
		ac.setCity_name(param.get("city_name").toString());
		ac.setCreator(param.get("userConde").toString());
		String fileUrl=param.get("fileUrl").toString();
		 if(fileUrl !=null ){
			 String[] fileUrlArr=fileUrl.split(",");
			 for(int i=0;i<fileUrlArr.length;i++){
				 CommunityImg ci=new CommunityImg();
				 ci.setImg_url(fileUrlArr[i]);
				 ci.setCommunity(ac);//在多方分别把一方放进去
				 ac.getCommunityimg().add(ci);
				 
			 }
			 
		 }
		
		int result =areaCommunityDao.addAreaCommunity(ac);
		if(result==1){
			map.put("success", true);
		}else{
			map.put("success", false);
		}
		return map;
	}

	@Override
	public Community getAreaCommunityDetail(Integer community_id) {
		 Map<String, Object> map=new HashMap<String,Object>();
		 Community c=areaCommunityDao.getAreaCommunityDetail(community_id);
		return c;
	}

	@Override
	public Map<String, Object> getAreaCommunityList(Map<String, Object> param) {
		Map<String, Object> map=new HashMap<>();
		List<Community> list=areaCommunityDao.getAreaCommunityList(param);
		map.put("rows", list);
		map.put("count",(int) areaCommunityDao.getAreaCommunityListCount(param));
		return map;
	}
	
	

}
